package com.oneday.ashop.console.base.spring;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.Permission;
import org.apache.shiro.cache.ehcache.EhCacheManager;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.util.List;

/**
 * springmvc基础拦截器
 * User:bob.yang
 * Date 2015/7/30 0030
 */
@Slf4j
public class BaseInterceptorAdapter extends HandlerInterceptorAdapter{


    private static final String SERVICEPATH = "//head/serviceCode";
    private static final String COMPANYIDPATH ="//body/companyId";

    /**
     * 在@Controller方法前进行拦截
     */
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) throws Exception {
        log.info("进入到拦截方法内，对报文进行一些预处理");
        String uri = request.getRequestURI();
        String contextPath = request.getContextPath();
//        if(!uri.equals("/base/login.htm")) {
//            Subject subject = SecurityUtils.getSubject();
//            boolean flag = subject.hasRole("admin");
//            if (flag || uri.equals("/base/login.htm")) {
//                return true;
//            }
//        }else {
            return true;
//        }
//        return false;
    }

    @Override
    public void postHandle(HttpServletRequest request,
                           HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {
    }

    /**
     * 在Controller方法后进行拦截
     */
    @Override
    public void afterCompletion(HttpServletRequest request,
                                HttpServletResponse response, Object handler, Exception ex)
            throws Exception {


    }

}
